<template>
	<view>
		<view class="header">
			<view class="home-content">
				<view class="home-title">{{ "部门下沉，共建一流" }}</view>
				<view class="home-item">
					<view
						class="home-items"
						v-for="(item, index) in itemList"
						:key="index">
						<uni-data-select
							:placeholder="item.name"
							v-model="value"
							:localdata="item.list"
							@change="gethyDemand(value, index)"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view class="build-content">
			<view class="content-header">
				<view class="title" v-for="(item, index) in Ranking" :key="index">
					{{ item.name }}
				</view>
			</view>
			<view v-if="hyRankList.length !== 0">
				<view
					class="content"
					v-for="(item, index) in hyRankList"
					:key="index"
					@click="getDetail(item)">
					<view class="content-item"> {{ index + 1 }}</view>
					<view class="content-item">{{ item.deptName }} </view>
					<view class="content-item"> {{ item.activityTimes }}</view>
				</view>
			</view>
			<view class="none" v-else>
				{{ "暂无数据" }}
			</view>
		</view>
	</view>
</template>

<script>
import api from "../../api/api";
export default {
	data() {
		return {
			rankType: 0,
			value: "",
			itemList: [
				{
					name: "全部街区",
					data: 1,
					desable: false,
					list: [],
				},
				{
					name: "全部社区",
					data: 2,
					desable: false,
					list: [],
				},
				{
					name: "时间排序",
					data: 3,
					desable: false,
					list: [
						{
							text: "2024",
							value: "2024",
						},
						{
							text: "2023",
							value: "2023",
						},
						{
							text: "2022",
							value: "2022",
						},
					],
				},
				{
					name: "综合排序",
					data: 4,
					desable: false,
					list: [
						{
							text: "综合排序",
							value: 0,
						},
						{
							text: "需求次数",
							value: 1,
						},
						{
							text: "解决次数",
							value: 2,
						},
					],
				},
			],
			Ranking: [
				{
					name: "名次",
				},
				{
					name: "部门名称",
				},
				{
					name: "活动次数",
				},
			],
			street: [],
			community: [],
			hyRankList: [],
			sysOrgCode: '',
		};
	},
	methods: {
		getDetail(val) {
			if(this.rankType !== 1){
				uni.navigateTo({
					url: "/pages/component/profileDetail?deptId=" + val.deptId+"&rankType="+this.rankType,
				});
			}
		},
		gethyDemand(val, index) {
			switch (index) {
				case 0:
					this.sysOrgCode = val
					var data = {
						deptId: this.sysOrgCode,
					};
					this.getRankInfo(data);
					this.itemList[1].list = [];
					var data = {
						pid: this.sysOrgCode,
					};
					api.queryDepartTreeSync(data).then((e) => {
						if (e.data.code == 0) {
							let datas = e.data.result;
							datas.forEach((item) => {
							  let child = {
								value: item.id,
								text: item.departName,
							  };
							  this.itemList[1].list.push(child);
							});
						}
					});
					break;
				case 1:
					var data = {
						deptId: val,
					};
					this.getRankInfo(data);
					break;
				case 2:
					var data = {
						createTime: val,
					};
					this.getRankInfo(data);
					break;
				case 3:
					var data = {
						rankType: val,
					};
					this.getRankInfo(data);
					this.rankType = val
				default:
					break;
			}
		},
		queryTreeList() {
			api.queryTreeList().then((e) => {
				var list = e.data.result;
				list.forEach((item) => {
					var child = {
						value: item.id,
						text: item.departName,
					};
					this.itemList[0].list.push(child);
				});
			});
		},
		getRankInfo(data) {
			api.getRankInfo(data).then((e) => {
				if (e.data.code == 200) {
					this.hyRankList = e.data.result.hyRankList;
				}
			});
		},
	},
	mounted() {
		this.queryTreeList();
		this.getRankInfo();
	},
};
</script>

<style lang="scss" scoped>
@import "./profile.scss";
</style>
